/*登录请求方法*/
function ajaxUserLogin(fun,params){
	var _a=window.location.host,
		//_url=_a=='www.wss2.0.com'?'logintest.xueersi.org':'login.xueersi.org';
		_url=_a=='www.xueersi.com'?'login.xueersi.org':'logintest.xueersi.org';
    $.ajax({
	type:"post",
		url:'/users/userLogin',
		dataType:"json",
		timeout:7000,
		data:params,
		success:function(msg){
			if(msg.sign==true){
				$("#casiframe").html('<iframe src="http://'+_url+'/cas/actlogin/?tk='+msg.casid+'" width="0" height="0" style = "display:none"></iframe>');
				fun(msg);
			}else{
				alert(msg.loginErrorMsg);
			}
		 },
		 error:function(){alert('数据读取错误..');}
	 });
}
/*注册请求方法*/
function ajaxUserReg(fun,params){
	 $.ajax({
		   type:"post",
		   url:'/users/aRegister',
		   dataType:"json",
		   timeout:100000,
		   data:params,
		   success:function(msg){
			   fun(msg);
		   },
		   error:function(){
			   alert('数据读取错误..');
		   }
	  });
}
/* 头部搜索  */
function head_search(){url='/course/search/';url+='grade:'+$('#head_grade').val()+'/';url+='subject:'+$('#head_subject').val()+'/';url+='keywords:'+$.trim($('#head_keywords').val())+'/';window.location.href=url;}
/* 头部登录暂无*/
function headUserLogin(){
	var username=$.trim($("#head_username").val());
	var password=$.trim($("#head_password").val());
	if(username=='邮箱/手机/用户名'){
		alert('请填写用户名！');
		return false;
	}
	var params="data[Cas][username]="+username+"&data[Cas][password]="+password;
	function fun(msg){
			if(msg.sign==true){
				$("#userInfo1").hide();
				$("#userInfo2").show();
				$("#userLoginname").html(username);
			}else{
				alert(msg.loginErrorMsg);
			}
	}
	ajaxUserLogin(fun,params);
}
/* 前台登录弹出框  */
function myUserLogin(){
	var username=$.trim($("#username").val());
	var password=$.trim($("#password").val());
	var params="data[Cas][username]="+username+"&data[Cas][password]="+password;
	function fun(msg){
	   if(msg.sign==true){
			$("#userBox").hide();
			$("#userInfo1").hide();
			$("#userInfo2").show();
			$("#userLoginname").html(username);
		}else{
			alert(msg.loginErrorMsg);
		}
	}
	ajaxUserLogin(fun,params);
}
/*
 * 发表评论登录弹出框
 */
function myCommentsLogin () {
    var username = $.trim($("#comments-username").val());
	var password = $.trim($("#comments-password").val());
    var params="data[Cas][username]="+username+"&data[Cas][password]="+password;
    function fun(msg){
	   if(msg.sign==true){
			$("#userBox").hide();
			$("#userInfo1").hide();
			$("#userInfo2").show();
			$("#userLoginname").html(username);
		}else{
			alert(msg.loginErrorMsg);
		}
	}
	ajaxUserLogin(fun,params);
};
/* 购物车登录弹出框  */
function myCartLogin(){
	var username=$.trim($("#username").val());
	var password=$.trim($("#password").val());
	var params="data[Cas][username]="+username+"&data[Cas][password]="+password;
	var _a=window.location.host,
		//_url=_a=='www.wss2.0.com'?'logintest.xueersi.org':'login.xueersi.org';
		_url=_a=='www.xueersi.com'?'login.xueersi.org':'logintest.xueersi.org';
	function fun(msg){
	   if(msg.sign==true){
		   $("#casiframe").html('<iframe src="http://'+_url+'/cas/actlogin/?tk='+msg.casid+'" width="0" height="0" style = "display:none"></iframe>');
			window.location.href="/shoppingcart/mycart/showLogin";
		}else{
			alert(msg.loginErrorMsg);
		}
	}
	ajaxUserLogin(fun,params);
}

// 购物车显示注册TAB
function showRegisterTab(){$('#register_tab').addClass('on');$('#login_tab').removeClass('on');$('#register_box').show();$('#login_box').hide();}
/* 购物车注册弹出框  */
function myCartReg(){
	   $('#reg_submit_bun').unbind('click');
	   var email=$.trim($("#email").val());
	   var password=$.trim($("#regpassword").val());
	   var confirm_password=$.trim($("#repassword").val());
	   var realname=$.trim($("#truename").val());
	   var phone=$.trim($("#mobile").val());
	   var phone_province=$.trim($("#phone_province").val());
	   var phone_city=$.trim($("#phone_city").val());
	   var grade_id=$.trim($("#grade").val());
	   var verificationCode=$.trim($("#code").val());
	   var allowClause=$.trim($("#provisions").val());
	   var ip_province=$.trim($("#ip_province").val());
	   var ip_city=$.trim($("#ip_city").val());
	   var params="email="+email+"&password="+password+"&confirm_password="+confirm_password+"&realname="+realname+"&phone="+phone+"&phone_province="+phone_province+"&phone_city="+phone_city+"&grade_id="+grade_id+"&verificationCode="+verificationCode+"&allowClause="+allowClause+"&ip_province="+ip_province+"&ip_city="+ip_city;
	   function fun(msg){
		  if(msg.sign==true){
			   $("#cartLogin").html('<div class="cartRegSucc"><img src="/img/smiling-face.gif" /><span class="cartRegWord">注册成功！</span><span id="timeSpan">3</span>秒后转入订单确认...</div>');
			   cartRegSuccClose();
			   setTimeout("makeOrder();",3000);
		   }else{
			   alert('注册失败！');
		   }
	   }
	   ajaxUserReg(fun,params);
	   }
/* 隐藏元素   */
function hideElement(element){$("#"+element).hide();}
/* 弹出小窗口的位置  */
function getElementPos(elementId){var ua=navigator.userAgent.toLowerCase();var isOpera=(ua.indexOf('opera')!=-1);var isIE=(ua.indexOf('msie')!=-1&&!isOpera);var el=document.getElementById(elementId);if(el.parentNode===null||el.style.display=='none'){return false;}var parent=null;var pos=[];var box;if(el.getBoundingClientRect){box=el.getBoundingClientRect();var scrollTop=Math.max(document.documentElement.scrollTop,document.body.scrollTop);var scrollLeft=Math.max(document.documentElement.scrollLeft,document.body.scrollLeft);return{x:box.left+scrollLeft,y:box.top+scrollTop};}else if(document.getBoxObjectFor){box=document.getBoxObjectFor(el);var borderLeft=(el.style.borderLeftWidth)?parseInt(el.style.borderLeftWidth):0;var borderTop=(el.style.borderTopWidth)?parseInt(el.style.borderTopWidth):0;pos=[box.x-borderLeft,box.y-borderTop];}else{pos=[el.offsetLeft,el.offsetTop];parent=el.offsetParent;if(parent!=el){while(parent){pos[0]+=parent.offsetLeft;pos[1]+=parent.offsetTop;parent=parent.offsetParent;}}if(ua.indexOf('opera')!=-1||(ua.indexOf('safari')!=-1&&el.style.position=='absolute')){pos[0]-=document.body.offsetLeft;pos[1]-=document.body.offsetTop;}}if(el.parentNode){parent=el.parentNode;}else{parent=null;}while(parent&&parent.tagName!='BODY'&&parent.tagName!='HTML'){pos[0]-=parent.scrollLeft;pos[1]-=parent.scrollTop;if(parent.parentNode){parent=parent.parentNode;}else{parent=null;}}return{x:pos[0],y:pos[1]};}
/* 搜索课程-添加商品到购物车  */
function shopcartAdd(id){var pos=getElementPos("img"+id);$.ajax({url:'/course/cart/'+id,type:'get',dataType:'html',success:function(msg){$("#shopcartBox").html(msg);$("#shopcartBox").show();var a=document.getElementById("shopcartBox");a.style.left=pos.x-450+"px";a.style.top=pos.y+"px";return true;}});}
// 添加到悬浮购物车
function addBuyCar(d){var _box=$(d).parents('tr'),_a=_box.find('td:first a'),_id=_a.attr('id');$.ajax({url:'/course/Acart/',type:'post',dataType:"json",data:'id='+_id,timeout:7000,success:function(msg){switch(msg.result){case 1:buyCarAnimate(d);if(msg.total[0]!=0){var _box=$('#buyCarBox').find('tbody');_box.empty();$.each(msg.cartList,function(i,n){buyCarCreatItem(i,n.pname,n.price,n.resale,n.pnum);});}$('#buyCarBox .buycar_count span').text(msg.total[0]);$('#buyCarBox .buycar_price_all span').text(msg.total[1]);$('#buyCarBtn a em').text(msg.total[0]);$('#index_xes div.list_nav div.navBox span.number').text(msg.total[0]);buyCarSetColor();break;case 2:alert('您已购买过此课程!');break;case 3:alert('添加到购物车失败!');break;default:break;}}});}
// 悬浮购物车隔行换色
function buyCarSetColor(){$('#buycar_list tbody tr:even').removeClass('gray');$('#buycar_list tbody tr:odd').addClass('gray');}
// 向悬浮购物车中添加内容
function buyCarCreatItem(id,name,price,resale,num){var _box=$('#buyCarBox').find('tbody'),_num=_box.find('tr').length,_serial=(_num<10)?('0'+(_num+1)):(_num+1);var _html='<tr id="cart'+id+'" class="gray">'+'	<td class="buycar_serial">'+_serial+'</td>'+'	<td class="buycar_title"><a href="/kc/'+id+'.html" target="_blank">'+name+'</a></td>'+'	<td class="buycar_num">'+num+'</td>'+'	<td class="buycar_price">￥'+resale+'</td>'+'	<td class="buycar_delete"><a href="javascript:void(0);">删除</a></td>'+'</tr>';_box.append(_html);}
// 添加到悬浮购物车特效
function buyCarAnimate(d){var _dom=$(d).parents('tr'),_btn=$('#buyCarBtn a em');var _wrap='<div id="buyCarAnimateWrap"></div>';$('body').append(_wrap);$('#buyCarAnimateWrap').css({top:_dom.offset().top,left:_dom.offset().left,width:_dom.width(),height:_dom.height()}).show();$('#buyCarAnimateWrap').animate({width:0,height:0,top:_btn.offset().top+5,left:_btn.offset().left},600,function(){$('#buyCarAnimateWrap').hide();});}
// 从悬浮购物车中删除
function buyCarDelete(id){$.ajax({url:'/shoppingcart/aDelCart/',type:'post',dataType:"json",data:'id='+id,timeout:7000,success:function(msg){if(msg.result==true){var _box=$('#buyCarBox').find('tbody');if(msg.total[0]==0){_box.html('<tr><td colspan="5" align="center">没有任何记录！</td></tr>');}else{_box.empty();$.each(msg.cartList,function(i,n){buyCarCreatItem(i,n.pname,n.price,n.resale,n.pnum);});}$('#buyCarBox .buycar_count span').text(msg.total[0]);$('#buyCarBox .buycar_price_all span').text(msg.total[1]);$('#buyCarBtn a em').text(msg.total[0]);$('#index_xes div.list_nav div.navBox span.number').text(msg.total[0]);buyCarSetColor();}}});}
// 清空购物车(用于悬浮购物车)
function buyCarClear(){$.ajax({url:'/shoppingcart/aEmptyCart/',type:'post',dataType:"json",timeout:7000,success:function(msg){if(msg.result==true){var _box=$('#buyCarBox').find('tbody');if(msg.total[0]==0){_box.html('<tr><td colspan="5" align="center">没有任何记录！</td></tr>');}else{_box.empty();$.each(msg.cartList,function(i,n){buyCarCreatItem(i,n.pname,n.price,n.resale,n.pnum);});}$('#buyCarBox .buycar_count span').text(msg.total[0]);$('#buyCarBox .buycar_price_all span').text(msg.total[1]);$('#buyCarBtn a em').text(msg.total[0]);$('#index_xes div.list_nav div.navBox span.number').text(msg.total[0]);}}});}
function buyCarIeHack(d,b,r){var wH=$(window).height();var wW=$(window).width();var sT=$(document).scrollTop();var dW=d.outerWidth();var dH=d.outerHeight();var T=wH-dH+sT-b;var L=wW-dW-r;d.css({position:'absolute',top:T,left:L});}
/* 搜索课程-课程的目录显示  */
function hoverShow(classid,indexid,divid){$("."+classid).hover(function(){var id=$(this).attr(indexid);var pos=getElementPos(id);$("#"+divid+id).show();var a=document.getElementById(divid+id);a.style.left=pos.x+10+"px";a.style.top=pos.y+20+"px";},function(){var id=$(this).attr(indexid);$("#"+divid+id).hide();});}
/* 购物车-形成订单  */
function makeOrder(type){$.ajax({url:'/shoppingcart/makecart/',type:'post',dataType:'html',success:function(msg){if(msg==0){var H=Math.max($('body').height(),$(window).height()),L=$('body').width()/2-235;var _mask='<div id="winMask" class="win-mask"><!--[if IE 6]><iframe frameborder="0" width="100%" height="100%" style="filter:alpha(opacity=0);opacity:0;"></iframe><![endif]--></div>';if($('#winMask').length==0){$('body').append(_mask);}$('#winMask').height(H).show();var pos=getElementPos("img");$("#cartLogin,.win-form-box:eq(0)").show();$("#cartname").focus();var b=document.getElementById("cartLogin");b.style.left=L+"px";b.style.top=pos.y-200+"px";var _scroll=$('#img').length>0?$('#img').offset().top:50;if(type=='register'){showRegisterTab();}return true;}if(msg==1){window.location.href="/orders/add/";return true;}else{var arr=new Array();arr=msg.split("@|@");var ids=new Array();ids=arr[0].split(",");alert(arr[1]);for(var i=0;i<ids.length;i++){tr=document.getElementById("cart"+ids[i]);tr.style.backgroundColor="#F5D3D3";}return false;}}});}
/* 购物车-余额付款方式切换  */
function paymenttype(){$("div[name=paymenttype_div]").each(function(i,n){$(this).hover(function(){$(this).css('background-color','#C8E4FC');$(this).css('cursor','pointer');},function(){$(this).css('background-color','#F9FCFE');});$(this).click(function(){document.getElementById('paymentradio'+i).checked=true;$("span[name=paymenttype]").attr('class','bold');$("#paymenttype"+i).attr('class','orangebold');$("div[name=payment]").slideUp();$("#payment"+i).slideDown("normal");});});}
/* 购物车-余额充值后跳转  */
function mypaymenttype(){var mypaymenttype=$("#mypaymenttype").val();if(mypaymenttype>=0){document.getElementById('paymentradio'+mypaymenttype).checked=true;$("#payment"+mypaymenttype).show();$("#paymenttype"+mypaymenttype).attr('class','orangebold');}}
/* 确认订单-获得优惠卷列表  */
function getCounpon(cid,sel_id){if(course[cid]==undefined){return false;}$("#"+sel_id).html('<option value="">选择奖学金</option>');var len=coupon.length;for(i=0;i<len;i++){if(coupon[i][3]==1){continue;}if(coupon[i][2]!=''){var _str=','+coupon[i][2]+',';if(_str.indexOf(','+cid+',')==-1){continue;}}addOption(i,sel_id);}}
/* 确认订单-优惠卷下拉式列表添加  */
function addOption(id,sel_id){var _html=$("#"+sel_id).html();$("#"+sel_id).html(_html+'<option value="'+coupon[id][0]+'">'+coupon[id][1]+'元-'+coupon[id][4]+'</option>');}
/* 确认订单-设置选中的优惠卷  */
function selCoupon(id){coupon[id][3]=1;}
/* 确认订单-切换收货地址  */
function changeAdd(){$("div[name=add_div]").each(function(i,n){$(this).hover(function(){$(this).css('background-color','#C8E4FC');$(this).css('cursor','pointer');},function(){$(this).css('background-color','#EBEBEB');});$(this).click(function(){document.getElementById('addradio'+i).checked=true;$("#add"+i).attr('class','orderadd');$("div[name=add]").slideUp();$("#add"+i).slideDown("normal");$("#otherAddText").slideUp();document.getElementById("other_add").checked=false;});});}
/* 省市区联动  */
function renderAreaSelect(){var country=$("#country").val();var defaults={s1:'register_province',s2:'register_city',s3:'register_country',v1:$("#province").val(),v2:$("#city").val(),v3:$("#country").val()};threeSelect(defaults);}
/* 课程详情页-评论显示/隐藏  */
function getFormShow(check_id1,check_id2,form_id){$("#"+form_id).hide();$("#"+check_id2).hide();$("#"+check_id1).click(function(){$("#"+check_id1).hide();$("#"+check_id2).show();$("#"+form_id).show();});$("#"+check_id2).click(function(){$("#"+check_id1).show();$("#"+check_id2).hide();$("#"+form_id).hide();});}
/* 课程详情页-评论列表  */
function courseCommentShow(id){$.ajax({url:'/course/commentlist/'+id,type:'get',dataType:'html',success:function(msg){$("#CommentsList").html(msg);}})}
/* 发表对课程的评论  */
function courseCommentAdd(id){var title=$("#comment_title").val();var content=$("#comment_content").val();if($.trim(title)==''){alert("请填写评论标题！");$("#comment_title").focus();return false;}if($.trim(content)==''){alert("请填写评论内容！");$("#comment_content").focus();return false;}else{$.ajax({url:'/course/commentadd/',type:'post',cache:false,data:'id='+id+'&title='+title+'&content='+content,dataType:'html',success:function(msg){switch(msg){case"1":window.location.href="/comment/history/"+id;break;case"2":alert("评论失败！");break;case"3":var pos=getElementPos("img"+id);$("#userBox").show();$("#username").focus();var b=document.getElementById("userBox");b.style.left=pos.x+260+"px";b.style.top=pos.y+"px";break;case"4":alert("一分钟内不能重复评论！");break;default:alert("你输入的字符: <<"+msg+">> 非法");break;}}})}}
/*  发表对课程的提问 subin  */
function courseQuestionAdd(id){var content=$("#question_content").val();if($.trim(content)==''){alert("请填写咨询内容！");$("#question_content").focus();return false;}else{$.ajax({url:'/course/questionadd/',type:'post',cache:false,data:'id='+id+'&content='+content,dataType:'html',success:function(msg){switch(msg){case"1":window.location.href="/question/questionlist/"+id;break;case"2":alert("发表咨询失败！");break;case"3":var pos=getElementPos("img"+id);$("#userBox").show();$("#username").focus();var b=document.getElementById("userBox");b.style.left=pos.x+260+"px";b.style.top=pos.y+"px";break;case"4":alert("一分钟内不能重复咨询！");break;default:alert("你输入的字符: <<"+msg+">> 非法");break;}}})}}
/* 老师详情页-标签切换 */
function selectTags(tagid,showContent,selfObj){var tag=document.getElementById(tagid).getElementsByTagName("li");var taglength=tag.length;for(i=0;i<taglength;i++){$("#tab"+i).attr('class','');}selfObj.className="on";for(i=0;j=document.getElementById("tagContents"+i);i++){j.style.display="none";}$("#"+showContent).show();}
/* 老师详情页-评论列表 */
function teacherCommentShow(id){$.ajax({url:'/teacher/commentlist/'+id,type:'get',dataType:'html',success:function(msg){$("#CommentsList").html(msg);}})}
/* 发表对老师的评论 */
function teacherCommentAdd(id){var title=$("#comment_title").val();var content=$("#comment_content").val();if($.trim(title)==''){alert("请填写评论标题！");$("#comment_title").focus();return false;}if($.trim(content)==''){alert("请填写评论内容！");$("#comment_content").focus();return false;}else{$.ajax({url:'/teacher/commentadd/',type:'post',cache:false,data:'id='+id+'&title='+title+'&content='+content,dataType:'html',success:function(msg){switch(msg){case"1":alert("感谢您评论,只要被选精华评论就可以获得10个金币哦！详情参考学员评论规范。");teacherCommentShow(id);break;case"2":alert("评论失败！");break;case"3":var pos=getElementPos("img"+id);$("#userBox").show();$("#username").focus();var b=document.getElementById("userBox");b.style.left=pos.x-440+"px";b.style.top=pos.y-180+"px";return false;break;case"4":alert("一分钟内不能重复评论！");break;default:alert("你输入的字符: <<"+msg+">> 非法");break;}}})}}
/* 确认订单  */
function confirmcheck(){if(($('#isinvoice1').attr('checked')==true)&&($.trim($("#invoicehead").val())=='')){alert('请填写发票抬头！');$("#invoicehead").focus();return false;}if(($('#isinvoice1').attr('checked')==true)&&($('input[name="data[addid]"]:checked').val()==undefined)){alert('请选择一个收货地址！');return false;}if(($('#isinvoice1').attr('checked')==true)&&($('#other_add').attr('checked')==true)&&($.trim($("#cod_name").val())=='')){alert('收货人姓名不能为空！');$("#cod_name").focus();return false;}if(($('#isinvoice1').attr('checked')==true)&&($('#other_add').attr('checked')==true)&&($.trim($("#cod_add").val())=='')){alert('详细地址不能为空！');$("#cod_add").focus();return false;}if(($('#isinvoice1').attr('checked')==true)&&($('#other_add').attr('checked')==true)&&($.trim($("#cod_phone").val())=='')){alert('联系电话不能为空！');$("#cod_phone").focus();return false;}}
/* 货到付款必填项判断  */
function codcheck(){if($.trim($("#cod_name").val())==''){alert('收货人不能为空！');$("#cod_name").focus();return false;}if($.trim($("#cod_add").val())==''){alert('详细地址不能为空！');$("#cod_add").focus();return false;}if($.trim($("#cod_phone").val())==''){alert('联系电话不能为空！');$("#cod_phone").focus();return false;}}
/* 邮编选择  */
function zipSelect(id){$.ajax({type:"GET",url:'/json/wss_zipcode.json?'+generateMixed(12),dataType:"json",timeout:7000,success:function(result){if(result!=''){$.each(result,function(i,j){if(i==id){var zipcode=j['zipcode'];$('#zipcode').attr('value',zipcode);}});}},error:function(){alert('数据读取错误..');}});}
/* 分页函数-信息回调函数  */
function pageselectCallback(page_index,jq){var page_index=parseInt(page_index)>0?parseInt(page_index):0;var urlPage=$("#urlPage").val()+page_index;var params=$("#params").val();$.ajax({url:urlPage,type:'post',dataType:'html',data:params,success:function(msg){$("#PaginationResult").html(msg);}});}
/*
 * 分页函数-底部页码显示部分
 * @param  edge:边沿显示页码数 display:中心显示页码数  per:每页显示信息数目  page_total:信息总数
 */
function initPagination(edge,display,per,page_total){$("#Pagination").pagination(page_total,{num_edge_entries:edge,num_display_entries:display,callback:pageselectCallback,items_per_page:per});}
/* 分页函数-渲染课程评论分页信息  */
function renderPagination_comments(per){var page_total=parseInt($("#pageTotal").val());if(page_total>0){initPagination(2,8,per,page_total);if(page_total<eval(parseInt(per)+1)){$("#Pagination").hide();}}else{$("#PaginationResult").html("<div align='center'>该课程暂无评论！</div>");}}
/*
 * 分页函数-底部页码显示部分(改进版)
 * @param  edge:边沿显示页码数 display:中心显示页码数  per:每页显示信息数目  page_total:信息总数
 */
function initPagination_2(edge,display,per,page_total){$("#course_Pagination").pagination(page_total,{num_edge_entries:edge,num_display_entries:display,callback:pageselectCallback_2,items_per_page:per});}
/* 老师详情页 - 课程分页信息回调函数  */
function pageselectCallback_2(page_index,jq){var page_index=parseInt(page_index)>0?parseInt(page_index):0;var urlPage=$("#course_urlPage").val()+page_index;$.ajax({url:urlPage,type:'post',dataType:'html',success:function(msg){$("#course_PaginationResult").html(msg);}});}
/*  课程详情页-加入收藏  */
function favoriteAdd(course_id){$.ajax({url:'/course/addFavorite/'+course_id,type:'post',dataType:'html',success:function(msg){var dialogBox=new initDialog({id:'dialogBox',bg:'dialogBox_Bg',width:350,height:120});if(msg=='0'){var H=Math.max($('body').height(),$(window).height()),L=$('body').width()/2-235;var _mask='<div id="winMask" class="win-mask"><!--[if IE 6]><iframe frameborder="0" width="100%" height="100%" style="filter:alpha(opacity=0);opacity:0;"></iframe><![endif]--></div>';if($('#winMask').length==0){$('body').append(_mask);}$('#winMask').height(H).show();var pos=getElementPos("img"+course_id);$("#cartLogin,.win-form-box:eq(0)").show();$("#cartname").focus();var b=document.getElementById("cartLogin");b.style.left=L+"px";b.style.top=pos.y-200+"px";var _scroll=$('#img'+course_id).length>0?$('#img'+course_id).offset().top:50;}else{dialogBox.open();var pos=getElementPos("img"+course_id);var b=document.getElementById("dialogBox");b.style.top=pos.y-100+"px";$('#favorite_tip').html(msg);}}});}
/*  课程搜索/详情页-登录弹出框  */
function courseLogin(course_id){
	var username=$.trim($("#username").val());
	var password=$.trim($("#password").val());
	var params="data[Cas][username]="+username+"&data[Cas][password]="+password;
	function fun(msg){
	   if(msg.sign==true){
			 callUserInfo();
			$('#winMask,#cartLogin,.win-form-box:eq(1)').hide();
			$("#userInfo1").hide();
			$("#userInfo2").show();
			$("#userLoginname").html(username);
			if(course_id>0){
				favoriteAdd(course_id);
			}
		}else{
			alert(msg.loginErrorMsg);
		}
	}
	ajaxUserLogin(fun,params);
};

/* 返回用户信息  */
function callUserInfo(){
	var _hostName = document.location.host;
	var url='http://' + _hostName + '/users/getSpUrl?jsoncallback=?';
	$.getJSON(url,function(d){
		var _order=d.ordernum!=null?d.ordernum:0,
			_user=d.name!=null?d.name:'';
		if(d.name!=null){
			$("#userInfo1,#userInfoLoading").hide();
            $("#userInfo2").show();
			$('#ordernum').text(_order);
			$('#userInfo2 .info1').text(_user+'同学，欢迎您来到学而思网校！');
			var htmlTitle = $($('.welcome_info')[1]);
			htmlTitle.html(''+_user+',欢迎您!&nbsp;&nbsp;&nbsp;<a href="http://i.xueersi.com/"  xes_id="banner14">个人中心</a>&nbsp;&nbsp;&nbsp;<a href="http://'+_hostName+'/users/logout/" xes_id="banner15">退出</a>');
		}else{
			$('#userInfo1').show();
			$('#userInfo2,#userInfoLoading').hide();
		}
	});
}

/* 课程搜索/详情页-注册弹出框  */
function courseReg(){
	$('#reg_submit_bun').unbind('click');
	var email=$.trim($("#email").val());
	var password=$.trim($("#regpassword").val());
	var confirm_password=$.trim($("#repassword").val());
	var realname=$.trim($("#truename").val());
	var phone=$.trim($("#mobile").val());
	var phone_province=$.trim($("#phone_province").val());
	var phone_city=$.trim($("#phone_city").val());
	var grade_id=$.trim($("#grade").val());
	var verificationCode=$.trim($("#code").val());
	var allowClause=$.trim($("#provisions").val());
	var ip_province=$.trim($("#ip_province").val());
	var ip_city=$.trim($("#ip_city").val());
	var params="email="+email+"&password="+password+"&confirm_password="+confirm_password+"&realname="+realname+"&phone="+phone+"&phone_province="+phone_province+"&phone_city="+phone_city+"&grade_id="+grade_id+"&verificationCode="+verificationCode+"&allowClause="+allowClause+"&ip_province="+ip_province+"&ip_city="+ip_city;
	var _a=window.location.host,
		//_url=_a=='www.wss2.0.com'?'logintest.xueersi.org':'login.xueersi.org';
		_url=_a=='www.xueersi.com'?'login.xueersi.org':'logintest.xueersi.org';
	function fun(msg){
	      if(msg.sign==true){
				$("#cartLogin").html('<iframe src="http://'+_url+'/cas/actlogin/?tk='+msg.casid+'" width="0" height="0" style = "display:none"></iframe><div class="cartRegSucc"><img src="/img/smiling-face.gif" /><span class="cartRegWord">注册成功！</span><span id="timeSpan">3</span>秒后自动关闭...</div>');
				cartRegSuccClose();
				callUserInfo();
			}else{
				alert(msg.regErrorMsg);
			}
   }
   ajaxUserReg(fun,params);
};
/*	注册成功弹出框2秒自动关闭  */
var regTimer=0,regInterval;
var timeText=3;
function cartRegSuccClose(){
	regInterval=setInterval(function(){
		if(regTimer>2){
			$('#winMask,#cartLogin,.win-form-box:eq(1)').hide();
			clearInterval(regInterval);
		}else{
			var timeText2 = timeText-regTimer;
			$('#timeSpan').text(timeText2);
			regTimer++;
	   }
   },1000);
};
